var start = {

    maintenance: function() {

    }
};

var add = {

};

var search = {

    autoCompleteItems: function(tags) {
		$('#' + variables.getElementSearchInputHTMLID()).autocomplete({
			minLength: 1,
			source: tags
		});
        $('#' + variables.getElementSearchInputHTMLID()).autocomplete({
			minLength: 0,
            source: function( request, response ) {
				$('tr[id=removableTableContent]').remove();
					var matcher = new RegExp( $.ui.autocomplete.escapeRegex( request.term ), "i" );
					response( $.grep( tags, function( item ){
					var temp = matcher.test( item );
					if(temp)
						$('<tr id="removableTableContent"><td>' + item + '</td></tr>').appendTo('.resultTableContent');
					return temp;
				})
				)
			;response(tags.slice(0, 10));}
			
        });
    },

    handleItemAutocompletion: function() {

	search.search();
	var elements = ["4093",
			"7400",
			"7402",
			"7403",
			"7404",
			"7405",
			"7407",
			"7408",
			"7410",
			"7411",
			"7414",
			"7420",
			"7430",
			"7432",
			"7440",
			"7446",
			"7474",
			"7475",
			"7486",
			"7495",
			"74121",
			"74123",
			"74125",
			"74132",
			"74137",
			"74138",
			"74153",
			"74188",
			"74192",
			"74193",
			"74240",
			"74241",
			"74243",
			"74244",
			"74245",
			"74248",
			"74266",
			"74373",
			"74374",
			"74393",
			"74592",
			"74652",
			"75188",
			"75189",
			"AD562 (K594PA1)",
			"M82C54-2RJ",
			"SD 338",
			"SF 358",
			"BD 140",
			"SD 340",
			"SF 357",
			"SF 369",
			"GF 147",
			"GF 105",
			"GF 301",
			"GC 122",
			"SF 829",
			"SC 239",
			"SF 245",
			"KT 853B",
			"KF 517",
			"SF 136",
			"SF 137",
			"SC 308",
			"SC 237",
			"SF 126",
			"SF 121",
			"SF 116",
			"SF 225",
			"SF 240",
			"SF 245",
			"SS 219",
			"SS 200",
			"TIC216M",
			"ER 900 (=DB3)",
			"TE6300/127/60",
			"1,499 MHz",
			"SCX15AN/SCX05DN",
			"TCA 2365",
			"MOC 3043",
			"B40C800",
			"B250C1500",
			"RS405L",
			"LM317T",
			"LM337T",
			"7805",
			"7905",
			"S202DS4",
			"BDX54B",
			"L200C",
			"ZD 5.1",
			"BZX85-C7V5",
			"1N4148",
			"B80C800",
			"7812",
			"7815",
			"ZD 4,7",
			"BD 139",
			"7875",
			"LM2940",
			"1N4007",
			"L6203",
			"SFH610A-1",
			"ILD74",
			"LM393",
			"SY360",
			"SY345",
			"SY356",
			"SY351",
			"MB104 (=SFH600)",
			"PC900V",
			"1N4002",
			"BC 337",
			"1N4005",
			"B40C3700/2200",
			"B250C1000",
			"B250D",
			"NE 555",
			"BC 327",
			"MAX182ACPI",
			"ADC0808",
			"AD7511",
			"HA3-5104-5",
			"AD7524 (PM7524)",
			"AD7512",
			"TL074",
			"MAX233",
			"SKB2/02 L5A",
			"EXO-3 (12,000MHz)",
			"EXO-3 (20,000MHz)",
			"EXO-3 (24,000MHz)",
			"HP 2630",
			"MAX903",
			"OPA 37 (OP37)",
			"REF02",
			"HA7-2620",
			"MAX691",
			"LM339",
			"MAX610",
			"LM301",
			"OPA 27 (OP27)",
			"PKD01"];

			var category = [
			]
        search.autoCompleteItems(elements);
    },
	search: function() {
	
		$(document).ready(function() {
			
			//TODO: manually trigger autocomplete search
		});
		//TODO: manuelles auswerten mittels durchlaufen einer for-schleife, → Array von Arrays
		//→ Werte eines unterarrays werden gegeneinander validiert, die liste wird für das focus
		//input element erstellt, exakt gleich bleibt der aufbau der temporären tabelle
	}
};

var overview = {
};

var main = {

	switchStart: function() {
		$('#navi-start').click(function() {
			$('#favicon').remove();
			$('<link id="favicon" type="image/x-icon" rel="shortcut icon" href="images/sw.ico" />').appendTo('head');
			$(document).attr("title", "Start");
		});
	},
	
	switchAdd: function() {
		$('#navi-add').click(function() {
			$('#favicon').remove();
			$('<link id="favicon" type="image/x-icon" rel="shortcut icon" href="images/rw.ico" />').appendTo('head');
			$(document).attr("title", "Hinzufügen");
		});
	},
	
	switchSearch: function() {
		$('#navi-search').click(function() {
			$('#favicon').remove();
			$('<link id="favicon" type="image/x-icon" rel="shortcut icon" href="images/wr.ico" />').appendTo('head');
			$(document).attr("title", "Suchen");
		});
	},
	
	switchOverview: function() {
		$('#navi-overview').click(function() {
			$('#favicon').remove();
			$('<link id="favicon" type="image/x-icon" rel="shortcut icon" href="images/ws.ico" />').appendTo('head');
			$(document).attr("title", "Übersicht");
		});
	},

	handleFaviconSwitch: function() {
	
		main.switchStart();
		main.switchAdd();
		main.switchSearch();
		main.switchOverview();
	}

};

var variables = {

	getElementSearchInputHTMLID: function() {
		return "elementSearchInput";
		}
};

$(document).ready(function() {

	$('#' + variables.getElementSearchInputHTMLID()).on("autocompleteselect", function(event, ui){$('tr[id=removableTableContent]').remove();
	$('<tr id="removableTableContent"><td>' + $('#' + variables.getElementSearchInputHTMLID()).val() + '</td></tr>').appendTo('.resultTableContent');} );

    //tab initialization
    $( "#tabs" ).tabs();

    //user logout
    $('.logoutButton').click(function() {

        //$("div[id*='tab']").hide();
    });
});